<?php
session_start();
$_SESSION['nick']="";
//requerimientos--------------------------------
require '../../../MApache/weblinx/weblinx.php';
require '../Forms/FrmAccess.php';
require '../Forms/FrmLinkToTerminal.php';
require '../Forms/FrmAbout.php';
require '../Forms/FrmMenu.php';
require '../Forms/FrmInformation.php';
require '../Forms/FrmHelp.php';
require '../Classes/Setter.php';
require '../Classes/Sentinel.php';
//----------------------------------------------
//Creación Setter
$setter=new Setter($configurationsPath="../Config");
/*
//Creación de objeto Ajax
$ajax=new Ajax();
$ajax->setImageLoading($imageLoading="../../../MApache/weblinx/Images/ajax_loader2.gif");

//Objetos necesarios de presentación
$stack=new Stack($basicCommandsPath="../Data");
$stack->loadBasicCommands();
*/
$page=new Page();
$page->setBodyEvents(array("onload"=>'"mueveReloj()"', "onkeyup"=>'"keypressed(event)"'));
$page->setCss("../Themes/".$setter->getTheme()."/skin.css");
//-----------------------

//Inicio de página-----
$page->start();
//$ajax->activate();
//$ajax->GETMethodSend();
//$ajax->POSTMethodSend();
//$stack->activate(TRUE);
$page->headEnd();
$page->bodyStart();
//---------------------

if($_GET['start']=="yes"){
	$frmAccess=new FrmAccess();
        $frmAccess->show();

}

else if(isset($_POST['aceptar'])){
	$sentinel=new Sentinel();
	$r=$sentinel->NickPasswordVerify($_POST['nick'],$_POST['password'],"usuarios","nick","password");
	
	if($r==true){
		$_SESSION['nick']=$_POST['nick'];
		
		//Hallar secciones a las que tiene derecho
		$dbOperator=new DbOperator($setter->getDataBaseHost(),$setter->getDataBaseUserName(),$setter->getDataBaseName(),$setter->getDataBasePassword());
		$dbOperator->connect();
		$idRol1=$dbOperator->consult("SELECT idRol FROM usuarios WHERE nick='".$_POST['nick']."'","yes");
		$sections=$dbOperator->consult("SELECT seccion FROM permisos WHERE idRol='".$idRol1[0]."'","yes");
		
                
                
		$_SESSION['sections']=$sections;
		
		//Hallar id de usuario
		$idUser=$dbOperator->consult("SELECT id FROM usuarios WHERE nick='".$_POST['nick']."'","yes");
		$_SESSION['idUser']=$idUser[0];
		
                $frmLinkToTerminal=new FrmLinkToTerminal($userNick=$_POST['nick'], $userPass=$_POST['password'],$sections);
                $frmLinkToTerminal->setVisible($visible=TRUE);
                
		
	}
	else{
		$frmAccess=new FrmAccess();
		$frmAccess->setErrorMessage("Nick y/o password incorrectos!!!");
		$frmAccess->show();
				
	}
}


$page->end();
?>